<?php
/**
 * RUBIK Solution & IT Development ltd.
 *
 * PROJECT		: x4you
 * COPYRIGHT	: 2009
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 *
 * @author			hoadn <hoadn@rubik.com.vn>
 * @package			[package name]
 *
 * Created on	: Dec 9, 2008
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

/**
 * Type for table static_list
 */
class STATIC_LIST_TYPE {
	public static $FLAG_SIZE_CATEGORY 	= 'fm_cate';
	public static $FORMAT_TITLE 	= 't_title';
	public static $FORMAT_STATUS_DELIVERY 	= 'od_sttus';
	public static $FORMAT_PAYMENT_METHOD 	= 'od_pment';
	public static $FORMAT_LOCATION_PAGE = 'loc_page';
	
	private $_arrayValues = null;
	
	public function __construct($db=null) {
		if (!$db) {
			$db = &SysDatabase::getInstance();
		}
		
		$sql = "SELECT * FROM static_list";
		$db->setQuery($sql);
		$cur = $db->query();
		$this->_arrayValues = array();
		while ( $row = mysql_fetch_object( $cur ) ) {
			$this->_arrayValues[$row->id] = $row;
		}
	}
	
	/**
	 * Get the STATIC_LIST_TYPE instance
	 * @return STATIC_LIST_TYPE
	 */
	public static function &getInstance() {
		static $instance;
		if (empty ($instance)) {
			$instance = new STATIC_LIST_TYPE();
		}
		return $instance;
	}
	
	/**
	 * Get the static_list object via id
	 * @param $id
	 * @return StaticListDTO
	 */
	public static function &getStaticListObjById($id) {
		$inst = &self::getInstance();
		return $inst->_arrayValues[$id];
	}
	
	/**
	 * Get the lable of the list item via id
	 * @param $id
	 * @return string
	 */
	public static function getLabelTextById($id) {
		$obj = self::getStaticListObjById($id);
		if (!$obj) {
			return '';
		}
		return SysDBLanguage::_($obj->text, 'static_list');
	}

	/**
	 * Get the lable of the list item via $type and value
	 * @param $type
	 * @param $value
	 * @return string
	 */
	public static function &getStaticListObjByValue($type, $value) {
		$inst = &self::getInstance();
		$arrObjs = $inst->_arrayValues;
		foreach ($arrObjs as $obj) {
			if ($obj->type == $type && $obj->value == $value) {
				return $obj;
			}
		}
		return null;
	}

	/**
	 * Get the lable of the list item via $type and value
	 * @param $type
	 * @param $value
	 * @return string
	 */
	public static function getLabelTextByValue($type, $value) {
		$obj = self::getStaticListObjByValue($type, $value);
		if (!$obj) {
			return '';
		}
		return SysDBLanguage::_($obj->text, 'static_list');
	}
}
?>